<template>
  <div class="user-info">
    <div class="bg-img">
      <el-image
        style="width: 100%; height: 100%"
        :src="bgImg"
        fit="cover"
      ></el-image>
    </div>
    <div class="user-info-content">
      <div class="content-detail">
        <div class="cover">
          <el-avatar
            :size="100"
            :src="info.avatar || defaultAvatar"
          ></el-avatar>
        </div>
        <div class="detail">
          <div class="user-name">{{ info.nickName }}</div>
          <div class="detail-bottom">
            <el-tooltip effect="dark" content="访客" placement="top">
              <span class="visitor"
                ><span>{{ info.visitor }}</span
                >访客</span
              >
            </el-tooltip>
            <el-tooltip effect="dark" content="账号名" placement="top">
              <span class="username"
                ><i class="el-icon-user-solid"></i>{{ info.username }}</span
              >
            </el-tooltip>
            <el-tooltip effect="dark" content="手机号" placement="top">
              <span class="phone"
                ><i class="el-icon-phone"></i
                >{{ info.phone ? info.phone : "未填写手机号" }}</span
              >
            </el-tooltip>
            <el-tooltip effect="dark" content="注册日期" placement="top">
              <span class="register-time"
                ><i class="el-icon-date"></i>{{ info.createTime }}注册</span
              >
            </el-tooltip>
          </div>
        </div>
      </div>
      <div class="content-introduction">
        <div><i class="el-icon-chat-line-square"></i></div>
        <div class="introduction">{{ info.introduction || "暂无简介" }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import defaultAvatar from "@/assets/defaultAvatar.png";
import bgImg from "@/assets/bgUser.jpg";
import { getUserInfo } from "@/api/user";
import userInfo from "@/utils/userInfo";
export default {
  name: "UserInfoView",
  data() {
    return {
      bgImg,
      defaultAvatar,
      info: {},
    };
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    // 获取用户信息
    async getUserInfo() {
      const user = userInfo.getUser();
      if (!user) {
        this.$router.push("/login");
        return;
      }
      const res = await getUserInfo(user.userId);
      this.info = res.data;
    },
  },
};
</script>

<style lang="less" scoped>
.user-info {
  height: 80%;
  border-radius: inherit;
  background-color: #fff;
  .bg-img {
    width: 100%;
    height: 60%;
  }
  .user-info-content {
    width: 100%;
    padding-left: 14px;
    .content-detail {
      display: flex;
      align-items: flex-end;
      .cover {
        position: relative;
        z-index: 100;
        margin-top: -50px;
      }
      .detail {
        width: 100%;
        height: 50px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        margin-left: 10px;
        .user-name {
          font-weight: 600;
        }
        .detail-bottom {
          font-size: 13px;
          color: #999;
          span {
            margin-right: 10px;
          }
          .visitor {
            span {
              font-size: 16px;
              color: black;
              margin-right: 2px;
            }
          }
          .username,
          .phone,
          .register-time {
            i {
              margin-right: 2px;
            }
          }
        }
      }
    }
    .content-introduction {
      margin-top: 10px;
      margin-left: 10px;
      display: flex;
      color: #999;
      font-size: 13px;
      .introduction {
        width: 80%;
        margin-left: 10px;
      }
    }
  }
}
// 解决el-image的图片显示问题
/deep/.el-image__inner {
  object-position: 100% 66%;
}
</style>